package com.bluemoon.model.test.dbImort.visitor;

import com.bluemoon.model.test.dbImort.visitor.file.*;
import com.bluemoon.model.test.dbImort.visitor.po.ExtractResultSet;
import com.google.common.collect.Lists;

import java.util.List;

/**
 * 业务：
 * 1.针对不同文件类型pdf/ppt/word..进行解析转为txt文本
 * 2.思路：解析器，针对不同文件的解析器，转为txt结果
 *
 * @author Jarod.Kong
 * @date 2021/1/13 11:40
 */
public class VisitorClient {
    public static void main(String[] args) {
        // 定义collector/visitor
        List<BaseResourceFile> resourceFiles = getResourceFiles();
        Extract2TxtVisitorManager visitorManager = new Extract2TxtVisitorManager();
        for (ResourceFile resourceFile : resourceFiles) {
            resourceFile.accept(visitorManager);
        }

        ExtractVisitor<Object> file2ResultSetVisitor = new ExtractFile2ResultSetVisitor<>();
        for (BaseResourceFile resourceFile : resourceFiles) {
            ExtractResultSet<Object> accept = resourceFile.accept(file2ResultSetVisitor);
            Object result = accept.getContent();
            System.out.println(result);
        }


    }

    private static List<BaseResourceFile> getResourceFiles() {
        return Lists.newArrayList(
                new TextFile("a.txt"),
                new PdfFile("b.pdf"),
                new WordFile("c.doc"),
                new WordFile("c.docx"),
                new PPTFile("d.ppt"),
                new PPTFile("d.pptx")
        );
    }
}
